package org.wz.complex.work.kit.code;

import cn.hutool.core.io.FileUtil;
import org.wz.complex.work.consts.PathConst;
import org.wz.complex.work.entity.auth.sysinfo.SysinfoMicro;
import org.wz.complex.work.entity.project.code.CodeVue;
import org.wz.complex.work.entity.project.generator.GeneratorVue;

import java.io.File;
import java.util.Arrays;

import static org.wz.complex.work.consts.PathConst.VUE_HTML;
import static org.wz.complex.work.consts.PathConst.VUE_JS;

public interface GenVueKit {


    static void gen(GeneratorVue vue, CodeVue project, SysinfoMicro micro) {
        genJs(vue, project, micro);
        genHtml(vue, project, micro);
    }

    static void genJs(GeneratorVue vue, CodeVue project, SysinfoMicro micro) {
        genJsDetail("vuewz", vue, project, micro);
        genJsDetail("vuemethod", vue, project, micro);
    }

    static void genJsDetail(String tag, GeneratorVue vue, CodeVue project, SysinfoMicro micro) {
        String a = micro.getRoute();
        String b = vue.getModule();
        String c = vue.getEntity();
        String abc = "/" + a + "/" + b + "/" + c;
        String templatePath = project.getTemplatePath();
        String file = templatePath + File.separator   + "js" + File.separator + tag + ".js";
        String content = FileUtil.readUtf8String(file);
        String projectPath = project.getProjectPath();
        String jsPath = projectPath + File.separator + VUE_JS + abc + File.separator + tag + ".js";
        //
        FileUtil.writeUtf8String(content, jsPath);
    }


    static void genHtml(GeneratorVue vue, CodeVue project, SysinfoMicro micro) {
        Arrays.asList("index", "dialog", "foot", "head", "menu", "query", "table")
                .forEach(tag -> genHtmlDetail(tag, vue, project, micro));
    }

    static void genHtmlDetail(String tag, GeneratorVue vue, CodeVue project, SysinfoMicro micro) {
        String a = micro.getRoute();
        String b = vue.getModule();
        String c = vue.getEntity();
        String abc = "/" + a + "/" + b + "/" + c;
        String templatePath = project.getTemplatePath();
        String file = templatePath + File.separator   + "html" + File.separator + tag + ".html";
        String content = FileUtil.readUtf8String(file);
        String projectPath = project.getProjectPath();
        String jsPath = projectPath + File.separator + VUE_HTML + abc + File.separator + tag + ".html";
        //
        FileUtil.writeUtf8String(content, jsPath);
    }


}
